package com.lfy.springcloud.controller;

import com.lfy.springcloud.entities.CommonResult;
import com.lfy.springcloud.entities.Payment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Api("Order")
@RestController
@RequestMapping("/order")
public class OrderController {
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;


    @ApiOperation(value = "add", nickname = "添加")
    @PostMapping("/add")
    public CommonResult<Integer> add(@RequestBody Payment payment) {
        CommonResult<Integer> commonResult = restTemplate.postForObject(PAYMENT_URL + "/payment/add", payment, CommonResult.class);
        return commonResult;
    }

    @ApiOperation(value = "getById",nickname = "根据id获取")
    @GetMapping("/getById")
    public CommonResult<Payment> getById(@RequestParam Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/getById?id="+id,CommonResult.class);
    }
    @GetMapping("/list")
    @ApiOperation(value = "list",nickname = "查询所有")
    public CommonResult<List<Payment>> list(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/list",CommonResult.class);
    }
    @GetMapping("/getDiscovery")
    @ApiOperation(value = "getDiscovery",nickname = "查询服务信息")
    public CommonResult<Object> getDiscovery(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/getDiscovery",CommonResult.class);
    }
}
